package com.newyear.LiveCommerceManagement.service.impl;

import dao.LiveCommerceDao;
import entity.LiveCommerce;
import org.apache.ibatis.session.SqlSession;
import com.newyear.LiveCommerceManagement.service.LiveCommerceService;
import utils.MyBatisUtil;

import java.util.List;

/**
 * @author 吴阳基
 * @datetime 2023/11/13 9:42
 */
public class LiveCommerceServiceImpl implements LiveCommerceService {
    @Override
    public List<LiveCommerce> list() {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        return sqlSession.getMapper(LiveCommerceDao.class).list();
    }

    @Override
    public LiveCommerce getById(int id) {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        return sqlSession.getMapper(LiveCommerceDao.class).getById(id);
    }

    @Override
    public int add(LiveCommerce liveCommerce) {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        int add = sqlSession.getMapper(LiveCommerceDao.class).add(liveCommerce);
        sqlSession.commit();
        return add;
    }

    @Override
    public int delete(int id) {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        int delete = sqlSession.getMapper(LiveCommerceDao.class).delete(id);
        sqlSession.commit();
        return delete;
    }
}
